**************************************************
********* Table 5 and Table A9.1: Ballot presence*
********* in MMDs pre and post redistricting *****
********* 2000 and 2010 **************************
**************************************************

* Used for calculating the unique counts of ballots_2021
ssc install unique

do "do_files/prep_GRACE_data/load_prep_GRACE_data.do"


unique ballots_2021 if redistrictinground==1 & ballot_mmd==1
scalar mmd_pre_2000 = r(unique)
unique ballots_2021 if redistrictinground==2 & ballot_mmd==1
scalar mmd_post_2000 = r(unique)
unique ballots_2021 if redistrictinground==3 & ballot_mmd==1
scalar mmd_pre_2010 = r(unique)
unique ballots_2021 if redistrictinground==4 & ballot_mmd==1
scalar mmd_post_2010 = r(unique)

scalar mmd_2000_pct_change = (mmd_post_2000 - mmd_pre_2000) / mmd_pre_2000
scalar mmd_2010_pct_change = (mmd_post_2010 - mmd_pre_2010) / mmd_pre_2010

mat mmd = mmd_pre_2000, mmd_post_2000, mmd_2000_pct_change, mmd_pre_2010, mmd_post_2010, mmd_2010_pct_change


* Gives the values for calculating pct change MMD ballot presence
quietly tab redistrictinground if ballot_mmd==1 & basket_latw == 1, matcell(latw_freq)
scalar latw_2000_pct_change = (latw_freq[2,1] - latw_freq[1,1])/ latw_freq[1,1]
scalar latw_2010_pct_change = (latw_freq[4,1] - latw_freq[3,1])/ latw_freq[3,1]
mat latw = (latw_freq[1..2,1] \ latw_2000_pct_change \ latw_freq[3..4,1] \ latw_2010_pct_change)'

quietly tab redistrictinground if ballot_mmd==1 & basket_latm == 1, matcell(latm_freq)
scalar latm_2000_pct_change = (latm_freq[2,1] - latm_freq[1,1])/ latm_freq[1,1]
scalar latm_2010_pct_change = (latm_freq[4,1] - latm_freq[3,1])/ latm_freq[3,1]
mat latm = (latm_freq[1..2,1] \ latm_2000_pct_change \ latm_freq[3..4,1] \ latm_2010_pct_change)'


mat table_5 = latw \ latm \ mmd

mat rownames table_5 = "Latinas" "Latinos" "MMD Ballots"
mat colnames table_5 = "Pre2000" "Post2000" "Pct Change 2000" "Pre2010" "Post2010" "Pct Change 2010"

esttab matrix(table_5)

* pausing for users who might be looping through all replication files
pause

